<template>
	<view class="container">
		<view class="layout">
			<view class="block-item" style="overflow: visible">
				<view class="label">快递单号</view>
				<view class="input-warp">
					<input class="input" v-model="state.refund_logistics_number" type="text" placeholder="请输入快递单号" />
				</view>
				<view class="label">快递公司</view>
				<view class="input-warp">
					<uni-data-select class="input" v-model="state.kuaidi_id" :localdata="state.range" placeholder="请选择快递公司"></uni-data-select>
				</view>
				<view class="btn-group">
					<view class="btn-submit" @click="submit">提交</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
import { reactive } from 'vue';
import { post } from '@/request/index.js';
import { onLoad } from '@dcloudio/uni-app';

const state = reactive({
	order_id: '',
	kuaidi_id: '',
	refund_logistics_number: '',
	range: []
});

onLoad((option) => {
	state.order_id = option.id;
	getListData();
});

//获取快递公司老板
const getListData = async () => {
	const res = await post('mm/kuaidiList');
	const { code, data } = res;
	if (code == 200) {
		state.range = data.map((item) => {
			return {
				value: item.id,
				text: item.name
			};
		});
	}
};

//提交售后快递寄回信息
const submit = async () => {
	const params = {
		order_id: state.order_id,
		kuaidi_id: state.kuaidi_id,
		refund_logistics_number: state.refund_logistics_number
	};
	const res = await post('mm/sendBack', params);
	const { code, message } = res;
	if (code == 200) {
		uni.showToast({
			title: message
		});
	}
};
</script>
